// pages/course/video/video.js

var util = require("../../utils/util.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // top-search-begin
    sorts: ["综合排序","销量优先","价格由高到低","价格由低到高"],
    indexHidden: false,
    searchResultHidden: true,

    params: {
      Param: { ParentLabelID: 0, AdaptationType: 0, PageIndex: 1, ShowIndexNum: 20, SortType: 0, PriceType: 0, IsVoiceMedia: 0 },
      Action: 6210
    },
    params2: {
      Param: {
        SearchKey: "",
        InPackeage: 0,
        InLive: 0,
        InEduVideo: 1,
        InEduVoice: 0,
        InCurr: 0,
        PageIndex: 1,
        ShowIndexNum: 20
      },
      Action: 18900
    },


    // top-search-end
    // swiper-begin
    swiper: {
      urls: ['http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',
        'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg',
        'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'],
      dots: true,
      autoplay: true,
      interval: 2000,
      duration: 500

    },
    // swiper-end
    // video-list-begin
    VideoList: [],
    // video-list-end
  },

  //component-select
  onShowResult: function () {
    var that = this;
    var params2 = this.data.params2;
    params2.Param.SearchKey = this.selectComponent('#select').onGetSearchKey();
    util.reqMedia(params2, function (value) {
      that.setData({
        VideoList: value.EduVideoList
      });
    });
    this.setData({
      searchResultHidden: false,
      indexHidden: true
    });

  },
  onPickerChange: function () {
    var index = this.selectComponent('#select').onGetIndex();
    var params = this.data.params;
    params.Param.SortType = index;
    var page = this;
    util.reqMedia(params, function (value) {
      page.setData({
        VideoList: value.VideoList
      });
    });
    this.setData({
      searchResultHidden: true,
      indexHidden: false
    });
  },
  onConfirm: function () {
    var ids = this.selectComponent('#select').onGetIds();
    var params = this.data.params;
    params.Param.AdaptationType = ids.AdaptationType;
    params.Param.PriceType = ids.PriceType;
    params.Param.Subject = ids.Subject;
    var page = this;
    util.reqMedia(params, function (value) {
      page.setData({
        VideoList: value.VideoList
      });
    });
    this.setData({
      searchResultHidden: true,
      indexHidden: false
    });
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var params = this.data.params;
    var that = this;
    util.reqMedia(params, function (value) {
      var VideoList = value.VideoList;
      that.setData({
        VideoList: VideoList
      });

    });


    //get swipers
    params.Param = {};
    params.Action = 3710;
    util.reqMedia(params, function (value) {
      var urls = [];
      var LiveAdvertList = value.EduVideoAdvertList;
      console.log(LiveAdvertList);
      for (let i = 0; i < LiveAdvertList.length; i++) {
        urls[i] = LiveAdvertList[i]['ImageUrl'];
      }
      var swiper = that.data.swiper;
      swiper.urls = urls;
      that.setData({
        swiper: swiper
      });

    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    wx.showLoading({
      title: 'loading'
    });
    setTimeout(function () {
      wx.hideLoading();
      wx.stopPullDownRefresh();
    }, 1000);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    wx.showLoading({
      title: '到底了',
    });
    setTimeout(function () {
      wx.hideLoading();
    }, 1000);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})



